/**
 * @author harae Feng 
 * @date 2019-10-20 14:49:53 
 * @Last Modified by: harae Feng
 * @Last Modified time: 2019-12-23 15:16:36
 * @Describe 铃声多多加密解密算法 Crypto模块DES算法
 */

 const crypto = require('crypto')
 const keyString = 'hikmpuF9'

 const des = {

    algorithm:{  ecb:'des-ecb',cbc:'des-cbc'  },
    encrypt:function(plaintext, iv){
        var key = new Buffer(keyString);
        var iv = new Buffer(iv ? iv : 0);
        var cipher = crypto.createCipheriv(this.algorithm.ecb, key, iv);
        cipher.setAutoPadding(true)  //default true
        var ciph = cipher.update(plaintext, 'utf8', 'base64');
        ciph += cipher.final('base64');
        return ciph;
    },
    decrypt:function(encrypt_text,iv){
        var key = new Buffer(keyString);
        var iv = new Buffer(iv ? iv : 0);
        var decipher = crypto.createDecipheriv(this.algorithm.ecb, key, iv);
        decipher.setAutoPadding(true);
        var txt = decipher.update(encrypt_text, 'base64', 'utf8');
        txt += decipher.final('utf8');
        return txt;
    }

};

// 解密
// console.log(des.decrypt(decodeURIComponent(`T1%2Fes7svv2tskHuFH%2F0jnpMz%2FkKQlJImoixgzDPIYbW9LWMHXrYRZ15DQQGWQFTratF2qKy079S9LWMHXrYRZzKpTDVxHdck7W6Pv6o3wzStyvU4NnAGYnl6yu%2Fsw42Uc9rePrANfDswJrfJlAEZOn%2BmulAg8yF6cMAXZgYFoxdxj6Tcu%2Blp0LKrbp2vh8y7heGCRdN9%2F%2FhNMs0EkJKtdx4n5f96ClHR9b3BNuJLyH5XXj97e%2BT7A5PygNWMlul0PxRmMYZHZZB5MMzVrcPs2%2Fkk5jbXpcwXsPPyuf3kGTtQuRnnV%2BgiCCzw5YfcWsMUPwyYZIk7N1A%2Fv9eneWIv8n6AdM8qrBvDE6RCaABVCZQta08slMsCIXgsjizlkvch9rXggHGCGxPu1UAmFzxd7Xb6ihcIPq87TIOOeD%2BS2g4IWZb20yN0gIkpRsw7f%2FcCDq4UX5bclIbWOhSuORJIGjEb5kF3TrpsPx0ld0FlLYW9Vd55UAG8og%3D%3D
// `)))

module.exports = des